var win = Titanium.UI.currentWindow;
Titanium.Media.showCamera({

  success:function(event)
  {
    var cropRect = event.cropRect;
    var image = event.media;

    Ti.API.debug('Our type was: '+event.mediaType);
    if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO)
    {
      var imageView = Ti.UI.createImageView({width:win.width,height:win.height,image:event.media});
      win.add(imageView); 
      
      var postButton = Ti.UI.createButton({
        title:'Oh Snap!',
        bottom:10,
        height:40,
        width:100
      });
      
      win.add(postButton);
      win.open();
      
      postButton.addEventListener('click', function(e){
		//if(e.postbutton){
		var win2 = Titanium.UI.createWindow({
		url:'post.js',
		image: image
		});
    //win.close();
	win2.open({modal:true});
	//}
});
    }
    else
    {
      alert("got the wrong type back ="+event.mediaType);
    }
  },
  cancel:function()
  {
  },
  error:function(error)
  {
    // create alert
    var a = Titanium.UI.createAlertDialog({title:'Camera'});

    // set message
    if (error.code == Titanium.Media.NO_CAMERA)
    {
      a.setMessage('Please run this test on device');
    }
    else
    {
      a.setMessage('Unexpected error: ' + error.code);
    }

    // show alert
    a.show();
  },
  saveToPhotoGallery:true,
  allowEditing:true,
  mediaTypes:[Ti.Media.MEDIA_TYPE_VIDEO,Ti.Media.MEDIA_TYPE_PHOTO],
});

/*var win = Ti.UI.currentWindow;

var photoOptions = Ti.UI.createView({
  top:10,
  height:'auto',
  width:'auto',
  layout:'vertical'
});

var galleryButton = Ti.UI.createButton({
  title:'Choose A Photo',
  top:10,
  height:40,
  width:200
});
photoOptions.add(galleryButton);

var cameraButton = Ti.UI.createButton({
  title:'Take A Photo',
  top:10,
  height:40,
  width:200
});
photoOptions.add(cameraButton);

var preview = Ti.UI.createImageView({
  top:10,
  height:150,
  width:150
});
photoOptions.add(preview);

var postButton = Ti.UI.createButton({
  title:'Oh Snap!',
  bottom:10,
  height:70,
  width:100
});
photoOpton.add(postButton);
win.add(photoOptions);
//win.add(postButton);

function handleImageEvent(event) {
  preview.image = event.media;
}

galleryButton.addEventListener("click", function(e) {
  Titanium.Media.openPhotoGallery({
   success:handleImageEvent
  });
});

cameraButton.addEventListener("click", function(e) {
  Titanium.Media.showCamera({
   success:handleImageEvent //you would also specify an error callback for when no camera is present
  });
});

postButton.addEventListener("click", function(e) {
  var xhr = Titanium.Network.createHTTPClient();
xhr.onload = function() {
var doc = this.responseXML.documentElement;
if (doc.getElementsByTagName("err") != null && doc.getElementsByTagName("err").length > 0) {
var a = Titanium.UI.createAlertDialog({
   title:'Well, this is awkward...',
   message: 'TwitPic error: '+doc.getElementsByTagName("err").item(0).getAttribute("msg")
   });
   a.show();
}
else {
var a = Titanium.UI.createAlertDialog({
       title:'Cool Beans!',
       message:'Your photo has been uploaded. Want to check it out?',
       buttonNames: ['OK','Cancel'],
       cancel: 1
      });
      
      a.addEventListener('click', function(e) {
       if (e.index == 0) {
       Ti.Platform.openURL(doc.getElementsByTagName("mediaurl").item(0).text)
       }
      });
      
   a.show();
}
};
xhr.open('POST','https://twitpic.com/api/uploadAndPost');
  xhr.send({
    media:preview.image,
    username:Ti.App.Properties.getString("un"),
    password:Ti.App.Properties.getString("pw"),
    message:'#ohsnap! I just uploaded this from my first #titanium app @oscon -'
  });
});*/